package io.github.shenbinglife.springboot2.layui.admin.entity;

import io.github.shenbinglife.springboot2.layui.common.model.BaseEntity;
import io.github.shenbinglife.springboot2.layui.common.model.TreeNode;

import javax.persistence.*;

@Entity
@Table(name = "tbl_sys_org")
public class Org extends BaseEntity {
    enum OrgType {
        unknown, company, department, team,
    }

    @Column(name = "parent_id")
    private Long parentId;
    private String name;
    @Enumerated(EnumType.STRING)
    private OrgType type;
    private Integer ordered;
    private String description;

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public OrgType getType() {
        return type;
    }

    public void setType(OrgType type) {
        this.type = type;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getOrdered() {
        return ordered;
    }

    public void setOrdered(Integer ordered) {
        this.ordered = ordered;
    }

    public TreeNode<Long> toTreeNode(Long parentId) {
        TreeNode<Long> tree = new TreeNode<>();
        tree.setId(getId());
        tree.setParentId(parentId);
        tree.setName(name);
        tree.setOrdered(ordered);
        tree.addAttr("desc", description);
        return tree;
    }
}
